package com.yjhb.android.sbz.fragment.mytask;

import com.yjhb.android.sbz.adapter.MyTaskListAdapter;
import com.yjhb.android.sbz.entity.MyTask;
import com.yjhb.android.sbz.fragment.BaseListFragment;
import com.yjhb.android.sbz.mvp.mytask.MyTaskListPresenter;
import com.yjhb.android.sbz.mvp.mytask.MyTaskListView;
import com.yjhb.android.sbz.tool.Tool;
import com.jojo.android.zxlib.tool.ZxToast;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/12/17 10:54
 */
public abstract class MyTaskListFragment extends BaseListFragment<MyTaskListPresenter, MyTaskListAdapter, MyTask> implements MyTaskListView {
    private final String TAG = "MyTaskListFragment";

    @Override
    protected MyTaskListAdapter getAdapter() {
        return new MyTaskListAdapter(getContext());
    }

    @Override
    protected CharSequence getTips() {
        return null;
    }


    @Override
    protected MyTaskListPresenter initPresenter() {
        return new MyTaskListPresenter(this);
    }

    @Override
    public void onItemClick(int index, Object o) {
        MyTask myTask = (MyTask) o;
        Tool.startEditTaskDetailActivity(getActivity(),myTask.getTaskId());
    }


    @Override
    public void onWait(String msg) {
        loadingDialog.setTipsText(msg);
        loadingDialog.show();
    }

    @Override
    public void onSuccess(String msg) {
        loadingDialog.cancel();
        ZxToast.showSuccessBottomToast(msg);
    }

    @Override
    public void onLoad(List<MyTask> myTasks) {
        smartRefreshLayout.finishLoadmore();
        dataSet.addAll(myTasks);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onRefresh(List<MyTask> myTasks) {
        smartRefreshLayout.finishRefresh();
        loadingDialog.cancel();
        dataSet.clear();
        dataSet.addAll(myTasks);
        adapter.notifyDataSetChanged();
    }

//    @Override
//    public void onFailure(int code, String msg) {
//        loadingDialog.cancel();
//        smartRefreshLayout.finishRefresh();
//        smartRefreshLayout.finishLoadmore();
//        ZxToast.showFAILBottomToast(msg);
//    }
}
